package com.example.TestJDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/* ━━━━━━佛祖保佑━━━━━━
 *                  ,;,,;
 *                ,;;'(    社
 *      __      ,;;' ' \   会
 *   /'  '\'~~'~' \ /'\.)  主
 * ,;(      )    /  |.     义
 *,;' \    /-.,,(   ) \    码
 *     ) /       ) / )|    农
 *     ||        ||  \)
 *     (_\       (_\
 * ━━━━━━永无BUG━━━━━━
 * @author ：zjq
 * @date ：2020/11/18 14:32
 * @description:                TODO  测试 Impala
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 */
public class ImpalaJDBCTest {


    public static void main(String[] args) throws Exception {
        ImpalaJDBCTest k = new ImpalaJDBCTest();
        k.testMyPre();
    }


    public void testMyPre() throws Exception {
//        String driverClass = "com.cloudera.impala.jdbc41.Driver";
//        String url = "jdbc:impala://localhost:21050";
        String driverClass = "org.apache.hive.jdbc.HiveDriver";
        String url = "jdbc:hive2://localhost:21050/;auth=noSasl";
        // 1. 加载 驱动
        Class.forName(driverClass);
        // 2. 获取连接
        Connection connection = DriverManager.getConnection(url);
        // 3. sql
//        String sql = "select distinct_id as distinctId,event as event ,time as time from mp_launch_kudu order by time limit 5";
        String sql = "select distinct_id as distinctId,event as event ,time as time from mp_launch_kudu  where time='2020-11-17 02:10:31.977' limit 1";
        // 4. 预编译 sql
        PreparedStatement ps = connection.prepareStatement(sql);

        // 5. 执行 sql
        ResultSet rs = ps.executeQuery();
        // 6. 打印
        while (rs.next()) {
            System.out.print(rs.getString(1) + "   ");
            System.out.print(rs.getString(2) + "   ");
            System.out.print(rs.getString(3) + "   ");
            System.out.println("  ");
        }
        // 7. 关闭连接
        rs.close();
        connection.close();
    }


}
